<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');

need_login();
$lotteries = array();

//找到抽奖的并且还未过有效期的团购，注意，如果超过兑奖有效期，抽奖号自动消失，因此，新建抽奖时注意
$daytime = strtotime(date('Y-m-d'));
$condition = array( 'team_type' => 'lottery', "expire_time > {$daytime}");
$teams = DB::LimitQuery('team', array(
	'condition' => $condition,
));
foreach($teams AS $key => $one){	
	$teams[$one['id']] = $one;
	unset($teams[$key]);
}
$team_ids = Utility::GetColumn($teams, 'id');


$condition = array( 'user_id' => $login_user_id, 'team_id' => $team_ids);
$lottery = DB::LimitQuery('lottery', array(
	'condition' => $condition,
));


//$lottery_ids = Utility::GetColumn($lottery, 'id');
$j = 0;
foreach($lottery AS $one){
	$j++;
	$condition = array( 'team_id' => $one['team_id'], "id <= {$one['id']}");	
	$one['lottery_num'] = Table::Count('lottery', $condition);
	$lotteries[$j] = $one;
}

$pagetitle = '我的抽奖';

include template('account_lottery');